import type { AxiosRequestConfig, AxiosResponse } from 'axios'

export interface CreateAxiosConfig extends AxiosRequestConfig {
  transform: AxiosTransform
}

export abstract class AxiosTransform {
  /**
   * @description: 请求之前的拦截器
   */

  requestInterceptors?: (
    config: AxiosRequestConfig,
    options: CreateAxiosConfig
  ) => AxiosRequestConfig

  /**
   * @description: 请求错误处理
   */
  requestInterceptorsCatch?: (error: Error) => void

  /**
   * @description: 响应错误处理
   */
  responseInterceptorsCatch?: (error: Error) => void

  /**
   * @description: 请求之后的拦截器
   */
  responseInterceptors?: (res: AxiosResponse<any>) => [error: string | null, data: any]
}

export interface Result<T = any> {
  message: string
  code: number
  data: T
}
